package com.weibo.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.weibo.db.DataBaseConnection;
import com.weibo.entity.JianceFenlei;
import com.weibo.entity.JianceWeibo;

public class JianceWeiboService  extends  DataBaseConnection{
	
	public void delete(int id){
		try {
			String sql = "delete from t_jiance_weibo where id="+id ;
				super.delete(sql);
			
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				super.closeAll();
			}
	}
	
	public void add(JianceWeibo wb){
		
		try {
			String sql = "insert into t_jiance_weibo(nicheng,weibo_id,fenlei_id,fenlei_name) " +
					"values ('"+wb.getNicheng()+"','"+wb.getWeibo_id()+"','"+wb.getFenlei_id()+"','"+wb.getFenlei_name()+"')";
				super.save(sql);
			
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				super.closeAll();
			}
	}
	
	
	public List<Object> findAll(){
		
		String sql = "select * from t_jiance_weibo";
		ResultSet rs=null;
		try {
			rs = super.getResultSet(sql, null);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		List<Object> list = new LinkedList<Object>();
		JianceWeibo wb = null;
		
		try {
			while(rs.next()){
				wb = new JianceWeibo();
				wb.setId(rs.getInt("id"));
				wb.setNicheng(rs.getString("nicheng"));
				wb.setWeibo_id(rs.getInt("weibo_id"));
				wb.setFenlei_id(rs.getInt("fenlei_id"));
				wb.setFenlei_name(rs.getString("fenlei_name"));
				list.add(wb);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally{
			super.closeAll();
		}
		return list;
	}
	
	
public List<JianceWeibo> list(){
		
		String sql = "select * from t_jiance_weibo";
		ResultSet rs=null;
		try {
			rs = super.getResultSet(sql, null);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		List<JianceWeibo> list = new LinkedList<JianceWeibo>();
		JianceWeibo wb = null;
		
		try {
			while(rs.next()){
				wb = new JianceWeibo();
				wb.setId(rs.getInt("id"));
				wb.setNicheng(rs.getString("nicheng"));
				wb.setWeibo_id(rs.getInt("weibo_id"));
				wb.setFenlei_id(rs.getInt("fenlei_id"));
				wb.setFenlei_name(rs.getString("fenlei_name"));
				list.add(wb);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally{
			super.closeAll();
		}
		return list;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
